package com.weiyin.examination.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.weiyin.examination.R;
import com.weiyin.examination.activity.QuestionTypeActivity;
import com.weiyin.examination.http.RetrofitClient;
import com.weiyin.examination.util.CoolImageLoader;
import com.weiyin.examination.util.LayoutHelper;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 *     e-mail : niejunfeng@win-electr.com
 *     time   : 2018/04/03
 *     desc   : 首页
 *     version: 1.0.0
 *     Copyright: Copyright（c）2017
 *     Company:上海蔚音电子科技有限公司
 * </pre>
 *
 * @author niejunfeng
 */
public class HomeFragment extends BaseFragment implements View.OnClickListener {
    public static final int DELAY_TIME = 2000;

    private View view;
    private Banner banner;
    private ImageView homeFragmentSimulation, homeFragmentTopics;
    private LayoutHelper layoutHelper;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.home_fragment_layout, null);
            layoutHelper = new LayoutHelper(getActivity());
            layoutHelper.scaleView(view);
            initView();
            initBanner();
        }
        return view;
    }

    public void initView() {
        banner = (Banner) view.findViewById(R.id.homeFragmentBanner);

        homeFragmentTopics = (ImageView) view.findViewById(R.id.homeFragmentTopics);
        homeFragmentSimulation = (ImageView) view.findViewById(R.id.homeFragmentSimulation);


        homeFragmentTopics.setOnClickListener(this);
        homeFragmentSimulation.setOnClickListener(this);
    }

    private void initBanner() {
        List<String> images = new ArrayList<>();

        images.add(RetrofitClient.BASE_URL + "/test/11.png");
        images.add(RetrofitClient.BASE_URL + "/test/22.png");

        banner.setBannerStyle(BannerConfig.NOT_INDICATOR);
        banner.setImageLoader(new CoolImageLoader());
        banner.setImages(images);
        banner.setDelayTime(DELAY_TIME);
        banner.start();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.homeFragmentTopics:
                Intent intent = new Intent();
                intent.putExtra("name","专题练习");
                intent.setClass(getContext(), QuestionTypeActivity.class);
                startActivity(intent);
                break;
            case R.id.homeFragmentSimulation:
                Intent intent1 = new Intent();
                intent1.putExtra("name","模拟考试");
                intent1.setClass(getContext(), QuestionTypeActivity.class);
                startActivity(intent1);
                break;
            default:
                break;
        }
    }
}
